#! /bin/bash

hosts="e131 e132"

for host in $hosts;
do
echo $host

# 设置 阿里云 yum 源
ssh $host "yum install -y wget  & wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo"

# 设置 kubernetes 国内源
ssh $host "cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF"

# 设置 docker-ce 国内源
ssh $host "wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo"

# 设置 epel-release源
ssh $host "wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo"

# 清理yum缓存
ssh $host "yum clean all  & yum makecache"

# 安装docker, kubeadm,kubectl,kubelet, 设置命令补齐, 设置定时时间同步
ssh $host <<EOF

yum install -y docker-ce
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
systemctl status docker

yum install -y kubeadm-1.11.3 kubectl-1.11.3 kubelet-1.11.3
systemctl enable kubelet

yum install -y bash-completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc


yum install -y yum-utils device-mapper-persistent-data lvm2 net-tools conntrack-tools wget vim  ntpdate libseccomp libtool-ltdl 

systemctl enable ntpdate.service
echo '*/30 * * * * /usr/sbin/ntpdate time7.aliyun.com >/dev/null 2>&1' > /tmp/crontab2.tmp
crontab /tmp/crontab2.tmp
systemctl start ntpdate.service

EOF

done
